<template>
	<view class="content">
		<view style="background-color: #2e91f6; color: #FFFFFF;padding: 30rpx;">
			<!-- {{userInfo}} -->
			<view class="top_name" style="font-size: 25rpx;">用户名：{{userInfo.username}}</view>
			<view class="loginout">
				<u-tag text="退出登录" @click="loginOut()" type="warning" shape="circleLeft"/>
			</view>
			<u-row gutter="16" class="top_count">
							<u-col span="6">
								<view class="demo-layout bg-purple">
									教工编号: {{userInfo.no}}
								</view>
							</u-col>
							<u-col span="6">
								<view class="demo-layout bg-purple-light">
									手机号码: {{userInfo.phone}}
								</view>
							</u-col>
				<!-- 	<u-col span="6" style="border-right: dotted 1px #f8f8f8;" @tap="toScore()">
						<view class="top_count_count">
							100分
						</view>
						<view class="top_count_des">
							评分
						</view>
					</u-col> -->
<!-- 					<u-col span="12">
						<view class="top_count_count">
							{{getDay(userInfo)}}天
						</view>
						<view class="top_count_des">
							注册时长
						</view>
					</u-col> -->
			</u-row>
			<u-row gutter="16" class="top_count" style="margin-top: 10px;">
				<u-col span="6">
					<view class="demo-layout bg-purple">
						专业: {{userInfo.major}}
					</view>
				</u-col>
				<u-col span="6">
					<view class="demo-layout bg-purple-light">
						所在院系: {{userInfo.college}}
					</view>
				</u-col>
			</u-row>
		</view>
		<view class="top_bar">
			<u-icon name="order" size="30" style="margin-right: 10rpx;"></u-icon>
			招生明细（截止到今天,共招学生数量:{{total}}）
		</view>
			<swiper class="swiper-box">
				<swiper-item class="swiper-item">
					<scroll-view scroll-y style="height: 100%;width: 100%;">
							<view class="order" v-for="(res, index) in items" :key="res.id">
								<view class="top">
									<view class="left">
										<u-icon name="home" :size="30" color="rgb(94,94,94)"></u-icon>
										<view class="store">{{ res.username }}</view>
									</view>
									<view class="right">{{$u.timeFormat(res.updateTime, 'yyyy-mm-dd hh:MM:ss')}}</view>
								</view>
								<view class="item">
									<view class="left">手机号码:{{res.phone}}</view>
									<view class="right">报考专业:{{res.major}}</view>
								</view>
								<view class="item">
									<view class="left">考试号码:{{res.stuNo}}</view>
									<view class="right">毕业学校:{{res.school}}</view>
								</view>
								<view class="item">
									<view class="cert_no">身份证:{{res.certNo}}</view>
								</view>
								<view class="bottom">
									<view class="logistics btn" @click="btn_detail(res)">查看详情</view>
									<view class="exchange btn" @click="btn_update(res)">编辑</view>
									<view class="evaluate btn" @click="btn_delete(res)">删除</view>
								</view>
							</view>
					</scroll-view>
				</swiper-item>
			</swiper>
			<u-modal v-model="delModal.show" :content="delModal.content" @confirm="confirm()" @cancel="cancel" :show-cancel-button="true"></u-modal>
			<u-modal v-model="detModal.show" :content="detModal.content"  @cancel="cancel" title="学生详细">
				<view class="form">
				<u-form ref="uForm">
					<view>
						<u-form-item border="true" label="学生姓名:" label-width="140">
							<u-input v-model="detItem.username" :disabled='true'/>
						</u-form-item>
						<u-form-item border="true" label="考生号码:" label-width="140">
							<u-input v-model="detItem.stuNo" :disabled='true'/>
						</u-form-item>
						<u-form-item border="true" label="手机号码:" label-width="140">
							<u-input v-model="detItem.phone"  maxlength="11" :disabled='true'/>
						</u-form-item>
						<u-form-item border="true" label="身份证:" label-width="140">
							<u-input v-model="detItem.certNo"  maxlength="18" :disabled='true'/>
						</u-form-item>
						<u-form-item border="true" label="报考专业:" label-width="140">
							<u-input v-model="detItem.major"  :disabled='true'/>
						</u-form-item>
						<u-form-item border="true" label="毕业学校:" label-width="140">
							<u-input v-model="detItem.school"  :disabled='true'/>
						</u-form-item>
						<u-form-item border="true" label="备  注:" label-width="140">
							<u-input v-model="detItem.addInfo"  placeholder="" :disabled='true'/>
						</u-form-item>
					</view>
				</u-form>
				</view>
			</u-modal>
			<u-modal v-model="upModal.show" @confirm="modify" :content="upModal.content"  @cancel="cancel" :show-cancel-button="true" title="编辑">
				<view class="form">
				<u-form ref="uForm">
					<view>
						<u-form-item border="true" label="学生姓名:" label-width="140">
							<u-input v-model="upItem.username" :disabled='true'/>
						</u-form-item>
						<u-form-item border="true" label="考生号码:" label-width="140">
							<u-input v-model="upItem.stuNo" :disabled='true'/>
						</u-form-item>
						<u-form-item border="true" label="手机号码:" label-width="140">
							<u-input v-model="upItem.phone"  maxlength="11" :disabled='false'/>
						</u-form-item>
						<u-form-item border="true" label="身份证:" label-width="140">
							<u-input v-model="upItem.certNo"  maxlength="18" :disabled='true'/>
						</u-form-item>
						<u-form-item border="true" label="报考专业:" label-width="140">
							<u-input v-model="upItem.major"  :disabled='false'/>
						</u-form-item>
						<u-form-item border="true" label="毕业学校:" label-width="140">
							<u-input v-model="upItem.school"  :disabled='false'/>
						</u-form-item>
						<u-form-item border="true" label="备  注:" label-width="140">
							<u-input v-model="upItem.addInfo"  placeholder="" :disabled='false'/>
						</u-form-item>
					</view>
				</u-form>
				</view>
			</u-modal>
	</view>
</template>
<script>
	import request from '../../util/request.js'
	import api from '../../util/api.js'
	import check from '../../util/check.js'
	export default {
		data() {
			return {
				height: 300,
				border:true,
				userInfo:null,
				title: 'Hello',
				profile:'',
				total: 0,
				items:[],
				detItem:'',
				detModal:{
					show: false,
					content:''
				},
				upItem:'',
				upModal:{
					show: false,
					content:''
				},
				delItem: '',
				delModal: {
					show: false,
					content: "您确定要移除!!!"
				},
			}
		},
		filters: {
			firstChar: function(value) {
				return value.substr(0, 1);
			}
		},
		onInit() {
			console.log("onInit");
		},
		onShow() {
			uni.getSystemInfo({
				success: function (res) {
					this.height = res.windowHeight;
					console.log('gaodu=', res.windowHeight)
				}
			})
			this.getItems();
		},
		onReady() {
			console.log('onReady');
		},
		onLoad() {
			this.userInfo = uni.getStorageSync("userInfo");
			if (this.userInfo == null) {
				uni.navigateTo({
					icon:'none',
					title:'请重新登陆',
					url:'../login/login'
				})
			};
		},
		methods: {
			btn_detail(param) {
				console.log('btn_detail = ', param);
				this.detModal.show = true;
				this.detItem = param;
			},
			btn_update(param) {
				console.log('btn_update = ', param);
				this.upModal.show = true;
				this.upItem = param;
			},
			btn_delete(param) {
				console.log('btn_delete = ', param);
				this.delModal.show = true;
				this.delItem = param;
			},
			getDay(val){
				let date=this.$u.timeFormat(val,'yyyy-mm-dd');
				return date;
			},
			//删除一个学生
			confirm() {
				console.log('confirm = ', this.delItem);
				request.post(api.studentDel, {
					teacheNo:this.delItem.teacherNo,
					username:this.delItem.username,
					phone: this.delItem.phone,
					certNo: this.delItem.certNo,
				}).then(response=>{
					console.log('b=', response);
					if (response.data.status == 1) {
						uni.showToast({
							icon:'none',
							title:'删除成功',
						})
						this.getItems();
					} else {
						uni.showToast({
							icon:'none',
							title:'删除失败' + response.data.msg
						})
					}
				}).catch(ex=>{
					console.log(ex);
					uni.showToast({
						icon:'none',
						title:'请求失败，请稍后再试',
					})
				})
			},
			//修改学生信息
			modify:function(){
				console.log('modify', this.upItem);
				request.post(api.updata, {
					teacheNo:this.upItem.teacherNo,
					username:this.upItem.username,
					phone: this.upItem.phone,
					certNo: this.upItem.certNo,
					stuNo:this.upItem.stuNo,
					major:this.upItem.major,
					school:this.upItem.school,
					addInfo:this.upItem.addInfo
				}).then(response=>{
					console.log('g=', response);
					if (response.data.status == 1) {
						uni.showToast({
							icon:'none',
							title:'修改成功',
						})
						this.getItems();
					} else {
						uni.showToast({
							icon:'none',
							title:'修改失败' + response.data.msg
						})
					}
				}).catch(ex=>{
					console.log(ex);
					uni.showToast({
						icon:'none',
						title:'请求失败，请稍后再试',
					})
				})
			},
			cancel() {
				console.log('cancel = ');
			},
			getProfile:function(){
				request.postf(api.profile,{
					id:this.userInfo.uid
				}).then(response=>{
					console.log(response);
					this.profile=response.data.data[0];
				}).catch(ex=>{
					console.log(ex);
					uni.showToast({
						icon:'none',
						title:'请求失败，请稍后再试',
					})
				})
			},
			getItems:function(){
				uni.showLoading({
					title:'数据加载中...'
				})
				request.post(api.studentList,{
					teacherName: this.userInfo.username
				}).then(res=>{
					console.log('getItems=', res);
					this.items=res.data.data.records;
					this.total=res.data.data.total;
					console.log(this.items);
					uni.hideLoading();
				}).catch(ex=>{
					console.log(ex);
					uni.showToast({
						icon:'none',
						title:'请求失败，请稍后再试',
					})
				})
			},
			loginOut(){
				uni.clearStorage();
				uni.showToast({
					icon:'none',
					title:'退出登录成功'
				})
				uni.navigateTo({
					url:'../login/login'
				})
			}

		}
	}
</script>

<style lang="scss" scoped>
	.order {
		width: 730rpx;
		background-color: #ffffff;
		margin: 20rpx auto;
		border-radius: 20rpx;
		box-sizing: border-box;
		padding: 20rpx;
		font-size: 28rpx;
		.top {
			display: flex;
			justify-content: space-between;
			.left {
				display: flex;
				align-items: center;
				.store {
					margin: 0 10rpx;
					font-size:32rpx;
					font-weight: bold;
				}
			}
			.right {
				color: $u-type-warning-dark;
			}
		}
		.item {
			display: flex;
			margin: 20rpx 0 0;
			.left {
				margin-right: 10rpx;
				width: 310rpx;
				image {
					width: 200rpx;
					height: 200rpx;
					border-radius: 10rpx;
				}
			}
			.right {
				margin-left: 10rpx;
				// padding-top: 20rpx;
				text-align: left;
				.decimal {
					font-size: 24rpx;
					margin-top: 4rpx;
				}
				.number {
					color: $u-tips-color;
					font-size: 24rpx;
				}
			}
			.cert_no {
				margin-right: 20rpx;
			}
		}
		.bottom {
			display: flex;
			margin-top: 40rpx;
			padding: 0 10rpx;
			justify-content: space-between;
			align-items: center;
			.btn {
				line-height: 52rpx;
				width: 160rpx;
				border-radius: 26rpx;
				border: 2rpx solid $u-border-color;
				font-size: 26rpx;
				text-align: center;
				color: $u-type-info-dark;
			}
			.evaluate {
				color: #DD524D;
				border-color: #DD524D;
			}
		}
	}
	.swiper-box {
		flex: 1;
		height:800px;
	}
	// .swiper-item {
	// 	height: 100%;
	// }
	.content {
		background-color: #f8f8f8;
		height: 100%;
	}
	.top_name{
		font-size: 32rpx;
		margin-bottom: 30rpx;
		text-align: center;
	}
	.loginout{
		position: absolute;
		top: 40rpx;
		right: 0;
	}
	.top_count_count{
		text-align: center;
		margin-bottom: 20rpx;
		font-size: 35rpx;
		font-weight: bold;
	}
	.info_list_title{
		border-left: solid 10rpx #d5eef0;
		padding: 0 10rpx;
		margin: 20rpx 0;
		font-size: 35rpx;
		font-weight: 500;
	}
	.top_count_des{
		text-align: center;
		color: #f4f4f5;
		
	}
	.top_bar{
		background-color: #aaffff;
		padding: 20rpx;
		font-weight: bold;
	}
	.updata {
		padding-top: 30rpx;
	}
	.tb_items_title {
		padding: 20rpx 30rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
		background-color: #e3eff8;
	}

	.tb_item {
		position: relative;
		display: flex;
		flex-wrap: wrap;
		flex-direction: row;
		align-items: center;
		justify-content: flex-start;
		background-color: #FFFFFF;
		padding: 20rpx;
		height: 120rpx;
		margin-bottom: 20rpx;
	}
	.tb_item_first {
		background-color: #007AFF;
		width: 60rpx;
		height: 60rpx;
		padding: 10rpx;
		color: #FFFFFF;
		font-weight: 500;
		display: inline;
		flex: 0;
	}
	.tb_item_title {
		flex: 1;
		padding-left: 10rpx;
		padding-right: 25rpx;
	}
	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}
	.text-area {
		display: flex;
		justify-content: center;
	}
	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
	.label{
			position: absolute; 
			top:0rpx;
			right: 1rpx;
			border-radius: 0rpx 0 0 0rpx !important;
	}
	.form {
		background-color: #FFFFFF;
		padding: 20rpx;
		/* height: 100%; */
	}
	.info_list_title {
		border-left: solid 10rpx #0095f0;
		padding: 0 10rpx;
		margin: 20rpx 0;
		font-size: 35rpx;
		font-weight: 500;
	}
</style>
